package org.hhy.cloud.crawl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.hhy.cloud.crawl.dao.DictionaryDataDao;
import org.hhy.cloud.crawl.entity.DictionaryData;
import org.hhy.cloud.crawl.service.DictionaryDataService;
import org.lht.boot.web.api.param.PagerResult;
import org.lht.boot.web.api.param.QueryParam;
import org.lht.boot.web.api.param.util.ParamMybatisUtil;
import org.lht.boot.web.service.impl.CrudTreeServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @Classname DictionaryDataImpl
 * @Description service实现类
 * @Date 2020/11/3 11:12 PM
 * @Created by yupeng
 */
@Service
@Slf4j
public class DictionaryDataImpl  extends CrudTreeServiceImpl<DictionaryData, String, DictionaryDataDao> implements DictionaryDataService {

    @Override
    public PagerResult<DictionaryData> typePage(QueryParam queryParam) {
        QueryWrapper<DictionaryData> queryWrapper = ParamMybatisUtil.toQueryWrapper(queryParam);
        queryWrapper.and(dataDictQueryWrapper -> dataDictQueryWrapper.isNull("pid").or().eq("pid",""));
        PagerResult<DictionaryData> page = ParamMybatisUtil.buildPage(queryParam);
        IPage<DictionaryData> iPage = dao.selectPage(page, queryWrapper);
        page.setTotal(iPage.getTotal());
        page.setRecords(iPage.getRecords());
        page.setTotalPages(iPage.getPages());
        return page;
    }
}
